
#include "mobility/vns/VNSMobility.h"
#include <vns/vehicle.h>


Define_Module(VNSMobility);


/**
 * Reads the updateInterval and the velocity
 *
 * If the host is not stationary it calculates a random position and
 * schedules a timer to trigger the first movement
 */
void VNSMobility::initialize(int stage)
{
    BaseMobility::initialize(stage);

}

void VNSMobility::finish(){
	vehicle = 0;
}

void VNSMobility::setVehicle(vns::Vehicle* veh){
	vehicle = veh;
}

void VNSMobility::update(){
	updatePosition();
}

/**
 * Calculate a new random position and the number of steps the host
 * needs to reach this position
 */
void VNSMobility::setTargetPosition()
{

}


/**
 * Move the host if the destination is not reached yet. Otherwise
 * calculate a new random position
 */
void VNSMobility::makeMove()
{
    fprintf(stderr,"makemove\n");
}

/** @brief Returns the current position at the current simulation time. */
Coord VNSMobility::getCurrentPosition(/*simtime_t_cref stWhen = simTime()*/) const {
	if( vehicle ){
		vns::Vec p = vehicle->getPosition();
		return  Coord(p.x(),p.y(),p.z());
	}
	return Coord(0.0,0.0,0.0);
}

/** @brief Returns the current speed at the current simulation time. */
Coord VNSMobility::getCurrentSpeed() const {
	if( vehicle ){
		vns::Vec d = vehicle->getDirection();
		return Coord(d.x(),d.y(),d.z()) * vehicle->getSpeed();
	}
	return Coord(0.0,0.0,0.0);
}

/*
void VNSMobility::fixIfHostGetsOutside()
{
    double dummy;

    handleIfOutside( PLACERANDOMLY, stepTarget, targetPos, stepSize, dummy );
}
*/
